import api from '../../../fetch/api'

export default {
    data() {
        return {

        }
    },
    created() {

    },
    methods: {
        // 重新生成按钮
        reBuild(){
            this.$refs.myReBuildBtn.reBuild()
        },
        getDefaultParams(){//获取不能缺少的默认的参数
            let self = this;
            let searchParams = self.searchParams,
                searchList = self.searchList,
                result = {};
                var itemreportDimension,itemdateFromTo;
                for (var key in searchList) {
                    if (searchList.hasOwnProperty(key)) {
                        var item = searchList[key];
                        if(item.name=='reportDimension'){
                            itemreportDimension = item;
                        }else if(item.name=='dateFromTo'){
                            itemdateFromTo = item;
                        }
                    }
                }
                if(!self.searchParams.reportDimension){
                    result.reportDimension = itemreportDimension.value;
                }
                if(!self.searchParams.statDateFromStr){
                    result.statDateFromStr = moment(itemdateFromTo.value[0]).format('YYYY-MM-DD HH:mm:ss');
                    result.statDateToStr = moment(itemdateFromTo.value[1]).format('YYYY-MM-DD HH:mm:ss');
                }
            return result;
        },
        getList() {
            var params = $.extend({}, this.otherParams, this.searchParams, this.getDefaultParams());
            this.getItemList(params);
        },
        //获取列表
        getItemList(aparams) {
            let self = this,
                params = {
                    page: this.pageNumber,
                    rp: this.pageSize
                };
            params = $.extend({}, params, aparams);
            API.park_vip.dailyReportList(params).then(res => {
                let data = res.data,
                    list = data.rows;
                self.tbodysInfo = list;
                self.total = data.total;
            }, err => { })
        },
        exportData() {
            let self = this;
            let params = {
            };
            params = $.extend({}, params, this.otherParams ,this.searchParams, this.getDefaultParams());
            self.showDialog("确认导出该报表?", '', function () {
                self.toExportAsync('/monthTicket/report/export.do', params);
            });
        },
        toRecreate(report) {
            let self = this;
            let params = {
                reportDimension: self.searchParams.reportDimension,
                parkId: report.parkId,
                statDateYear: report.statDateYear,
                statDateMonth: report.statDateMonth,
                statDateDayStr: report.statDate
            };
            if(params.reportDimension=='custom'){
                var dateArr = report.statDateDisplay.split('至');
                var statDateFromStr = dateArr[0];
                var statDateToStr = dateArr[1];
                params.statDateFromStr = statDateFromStr;
                params.statDateToStr = statDateToStr;
            }
            self.showDialog("确认重新生成报表?", '', function () {
                API.park_vip.dailyReportRecreate(params).then(res => {
                    self.getList();
                    self.showToast('重新生成成功');
                }, err => {
                    self.getList(); 
                });
            });
        },
        toExportDetail(report) {
            let self = this;
            let params = {
                parkId:report.parkId
            };
            var date = report.statDateDisplay;
            switch (self.searchParams.reportDimension) {
                case 'day':
                    params['operateFrom'] = moment(date, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
                    params['operateTo'] = moment(date, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
                    break;
                case 'month':
                    params['operateFrom'] = moment(date, 'YYYY-MM').startOf('month').format('YYYY-MM-DD HH:mm:ss');
                    params['operateTo'] = moment(date, 'YYYY-MM').endOf('month').format('YYYY-MM-DD HH:mm:ss');
                    break;
                case 'year':
                    params['operateFrom'] = moment(date, 'YYYY').startOf('year').format('YYYY-MM-DD HH:mm:ss');
                    params['operateTo'] = moment(date, 'YYYY').endOf('year').format('YYYY-MM-DD HH:mm:ss');
                    break;
                case 'custom':
                    params['operateFrom'] = date.split("至")[0] + " 00:00:00";
                    params['operateTo'] = date.split("至")[1] + " 23:59:59";
                    break;
                default:
                    params['operateFrom'] = moment(date, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
                    params['operateTo'] = moment(date, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
            }
            self.showDialog("确认导出详情报表?", '', function () {
                // API.park_vip.vipWaterExport(params).then(res => {
                //     self.showToast('导出成功');
                //     window.location.href = encodeURI("/mgr/common/download.do?fileName=" + res.data);
                // }, err => { });
                self.toExportAsync('/vip/vipOperation/exportVipOperation.do', params);
            });
            //vipWaterExport
        },
    },
    filters: {

    }

}